package travianBot.botScripts;

import java.util.ArrayList;
import java.util.HashMap;


public class ScriptContainer {
	ArrayList<TravianScript> 		scriptList 	  = new ArrayList<TravianScript>();
	HashMap<Integer,TravianScript> 	scriptLineMap = new HashMap<Integer,TravianScript>();	
	HashMap<String,String> 			scriptSessionInfo = new HashMap<String,String> (); //structure for passing session state around
	
	int position=0;
	
	public void addScript(TravianScript resourceScript){
		scriptList.add(resourceScript);
		scriptLineMap.put(scriptList.size()-1, resourceScript);
	}
	
	/**
	 * store the script, with an id to retrieve it
	 * @param resourceScript
	 * @param lineNumber
	 */
	public void addScript(TravianScript resourceScript, int id){
		scriptList.add(resourceScript);
		scriptLineMap.put(id, resourceScript);
	}
	
	public TravianScript getNextScript(){
		TravianScript script = null;
		
		if( position != scriptList.size()){
			script = scriptList.get(this.position);
			position += 1;
		}		
		
		return script;
	}
	
	/**
	 * reset the cursor back to the start, and refresh the script session
	 */
	public void backToStart(){
		position = 0;
		
		// for each script, run the init method
		for (TravianScript script : this.scriptList) {
			script.initialiseSession(this.scriptSessionInfo);
		}
		
	}

	public HashMap<String, String> getScriptSessionInfo() {
		return scriptSessionInfo;
	}
}
